procedure getMfgFactor:
    define input parameter vPart as character.
    define input parameter vYear as integer.
    define input parameter vMonth as integer.
    define input parameter vPeriod as integer.
    define output parameter vFactor as decimal.

    define variable i as integer.
    define variable j as integer.
    define variable sdate as date.
    define variable ym as character.

    j = 0.
    vFactor = 0.
    sdate = date(vMonth, 1, vYear).

    do i = 1 to vPeriod:
        sdate = date(month(sdate - 1), 1, year(sdate - 1)).
        ym = string(year(sdate), "9999") + "M" + string(month(sdate), "99").

        find first qad_wkfl no-lock where qad_key1 = "MFG:" + vPart and qad_key2 = ym no-error.
        if available qad_wkfl then do:
            j = j + 1.
            vFactor = vFactor + qad_decfld[1].
        end.
    end.

    vFactor = (vFactor + (vPeriod - j) * 1.003) / vPeriod.
end.

procedure getSubFactor:
    define input parameter vPart as character.
    define input parameter vYear as integer.
    define input parameter vMonth as integer.
    define input parameter vPeriod as integer.
    define output parameter vFactor as decimal.

    define variable i as integer.
    define variable j as integer.
    define variable sdate as date.
    define variable ym as character.

    j = 0.
    vFactor = 0.
    sdate = date(vMonth, 1, vYear).

    do i = 1 to vPeriod:
        sdate = date(month(sdate - 1), 1, year(sdate - 1)).
        ym = string(year(sdate), "9999") + "M" + string(month(sdate), "99").

        find first qad_wkfl no-lock where qad_key1 = "SUB:" + vPart and qad_key2 = ym no-error.
        if available qad_wkfl then do:
            j = j + 1.
            vFactor = vFactor + qad_decfld[1].
        end.
    end.

    vFactor = (vFactor + (vPeriod - j) * 1.009) / vPeriod.
end.

procedure getLotVarFactor:
    define input parameter vPart as character.
    define input parameter vWoqty as decimal.
    define output parameter vFactor as decimal.

    vFactor = 1.
    
    if can-find(first pt_mstr where pt_part = vPart and CAN-FIND(FIRST code_mstr WHERE code_fldname = "pt_prod_line" 
        AND code_value = pt_prod_line AND code_cmmt = "10")) then return.

    find first qad_wkfl no-lock where qad_key1 = "LBR-FACTOR" and qad_intfld[1] <= vWoqty and qad_intfld[2] >= vWoqty no-error.

    if available qad_wkfl then
        vFactor = qad_decfld[1].
end.

PROCEDURE getBalFactor :

    DEFINE INPUT PARAMETER vProdLine AS CHARACTER.
    DEFINE INPUT PARAMETER vSite     AS CHARACTER.

    DEFINE OUTPUT PARAMETER vFactor AS DECIMAL.

    vFactor = 1.06.
    /*
    IF vProdLine = "110" AND NOT (vSite BEGINS "21") THEN
        vFactor = 1.06.

    IF vProdLine = "120" AND NOT (vSite BEGINS "22") THEN
        vFactor = 1.06.

    IF vProdLine = "140" AND NOT (vSite BEGINS "26") THEN
        vFactor = 1.06.
    */
END PROCEDURE.

